package com.asdf.application.commands;

import java.util.List;

import com.asdf.application.Constants;
import com.asdf.external.INetserviceSimulator;
import com.asdf.external.LogWriter;

/**
 * @author Artem Barger
 * 
 * Performs the initialization of the entire system after receiving the
 * init command from command line.
 *
 */
public class InitCommand implements ICommandLine
{

	private final int AIRPORT_XML_INDEX = 1;
	private final int CLUBS_XML_INDEX = 2;
	
	@Override
	public void execute( INetserviceSimulator simulator, List<String> parameters)
	{
		if ( null == parameters || null == simulator)
		{
			LogWriter.getInstance( ).reportError( Constants.ILLEGAL_PARAMETERS_MSG + this.getClass( ));
			return;
		}
		
		if ( parameters.size( ) != Constants.INIT_PARAMETERS_NUMBER)
		{
			LogWriter.getInstance( ).reportError( Constants.ILLEGAL_PARAMETERS_NUMBER_MSG + this.getClass( ));
			return;
		}
		
		if ( !simulator.init( parameters.get( AIRPORT_XML_INDEX), parameters.get( CLUBS_XML_INDEX)))
		{
			LogWriter.getInstance( ).reportError( Constants.INITIATION_FAILED + this.getClass( ));
		}
		return;
	}

}
